package ca.cbc.giscommon.entity;

import com.vividsolutions.jts.geom.Geometry;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "source")
public class Source implements Cloneable, Serializable {

    private static final long serialVersionUID = -2065543939480863628L;
    private long id;
    private String name;
    private Category category;
    private String description;
    private String link;
    private String sourceType;
    private boolean digestFlag;
    private EventSubcategory eventSubcategory;
    private Geometry defaultGeom;
    private boolean cbcContent;

    public Source() {
    }

    public Source(String name, Category category, String description, String link, String sourceType, 
    		EventSubcategory eventSubcategory, Geometry defaultGeom, boolean isCBCContent) {
    	this(name, category, description, link, sourceType, true, eventSubcategory, defaultGeom, isCBCContent);
    }
    
    public Source(String name, Category category, String description, String link, String sourceType,
                  boolean digestFlag, EventSubcategory eventSubcategory, Geometry defaultGeom, boolean isCBCContent) {
        this.setName(name);
        this.setCategory(category);
        this.setDescription(description);
        this.setLink(link);
        this.setSourceType(sourceType);
        this.setEventSubcategory(eventSubcategory);
        this.setDigestFlag(digestFlag);
        this.setDefaultGeom(defaultGeom);
        this.setCbcContent(isCBCContent);
    }
    @Column(name = "is_cbc_content")
    public boolean getCbcContent() {
		return cbcContent;
	}

	public void setCbcContent(boolean isCBCContent) {
		this.cbcContent = isCBCContent;
	}

	@Override
    public Source clone() throws CloneNotSupportedException {
        return (Source) super.clone();
    }

    public boolean equals(Object obj) {
        if (obj.getClass().equals(Source.class) && ((Source) obj).getId() == this.getId()) {
            return true;
        }
        return false;
    }

    @ManyToOne
    @JoinColumn(name = "category_id")
    public Category getCategory() {
        return category;
    }

    @Column(name = "default_geom")
    @Type(type = "org.hibernatespatial.GeometryUserType")
    public Geometry getDefaultGeom() {
        return defaultGeom;
    }

    public String getDescription() {
        return description;
    }

    @ManyToOne
    @JoinColumn(name = "event_subcategory_id")
    public EventSubcategory getEventSubcategory() {
        return eventSubcategory;
    }

    public void setDigestFlag(boolean digestFlag) {
        this.digestFlag = digestFlag;
    }

    @Column(name = "digest_flag")
    public boolean getDigestFlag() {
            return digestFlag;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public long getId() {
        return id;
    }

    @Column(name = "source_type")
    public String getSourceType() {
        return sourceType;
    }

    public String getLink() {
        return link;
    }

    public String getName() {
        return name;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public void setDefaultGeom(Geometry defaultGeom) {
        this.defaultGeom = defaultGeom;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setEventSubcategory(EventSubcategory eventSubcategory) {
        this.eventSubcategory = eventSubcategory;
    }

    public void setId(long id) {
        this.id = id;
    }


    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return new StringBuffer("Source {id:").append(id)
                .append(", name:").append(name)
                .append(", category:").append(category)
                .append(", description:").append(description)
                .append(", link:").append(link)
                .append(", sourceType:").append(sourceType)
                .append(", eventSubcategory:").append(eventSubcategory)
                .append(", defaultGeom:").append(defaultGeom)
                .append(", isCBCContent:").append(cbcContent)
                .append("}").toString();
    }
}
